package com.weng.coder.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.weng.coder.entity.CoderCondition;
import com.weng.coder.mapper.CoderConditionMapper;
import com.weng.coder.service.ICoderConditionService;
import com.weng.framework.core.model.ResponseData;
import com.weng.framework.dao.mybatis.service.BaseServiceImpl;
import com.weng.framework.dao.mybatis.model.page.PageModel;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;


/**
 * 查询条件属性 服务实现类
 *
 * @author weng
 * @date 2021-04-16 16:08:14
 *
 */ 
@Slf4j
@Service
public class CoderConditionServiceImpl extends BaseServiceImpl<CoderConditionMapper, CoderCondition> implements ICoderConditionService {
	@Autowired
	private CoderConditionMapper coderConditionMapper;

	@Override
	public List<CoderCondition> findByTableId(String tableId){
		QueryWrapper<CoderCondition> qw = new QueryWrapper<>();
		qw.eq("table_id", tableId);
		return coderConditionMapper.selectList(qw);
	}

	/**
	 * 分页查询查询条件属性
	 * @return
	 */
	@Override
	public IPage<CoderCondition> list(Integer pageNo,Integer pageSize) {
		QueryWrapper<CoderCondition> qw = new QueryWrapper<>();
		IPage<CoderCondition> page = new PageModel<>(pageNo,pageSize);
		return coderConditionMapper.selectPage(page,qw);
	}


	/**
	 * 获取单个查询条件属性
	 * @param id
	 * @return
	 */
	@Override
	public CoderCondition getById(Serializable id) {
		return super.getById(id);
	}

	/**
	 * 新增单个查询条件属性
	 * @param coderCondition
	 * @return
	 */
	@Override
	public CoderCondition add(CoderCondition coderCondition)  {
		
		coderConditionMapper.insert(coderCondition);
		return coderCondition;
	}

	/**
	 * 更新单个查询条件属性
	 * @param coderCondition
	 * @return
	 * @
	 */
	@Override
	public int update(CoderCondition coderCondition)  {
		
		return coderConditionMapper.updateById(coderCondition);

	}


	@Override
	public ResponseData removeByIds(String ids) {
		String[] coderConditionIds = ids.split(",");
		boolean flag = this.removeByIds(Arrays.asList(coderConditionIds));
		if (flag) {
			return ResponseData.success();
		} else {
			return ResponseData.success();
		}
	}

}
